package com.itheima.swagger.controller;

import com.itheima.swagger.entity.Student;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("stu")
public class HelloController implements HelloControllerInterface {

    /**
     * 测试无参数接口地址
       无参：get  http://ip:port/rootPath/stu/hello
     */
    @Override
    @ApiOperation("对方法功能描述,无参测试")
    @GetMapping("hello")
    public String hello() {
        return "hello";
    }

    /**
     * 测试 queryString 风格的参入参数
       QueryString(问号传参)：
       get	http://ip:port/rootPath/stu?num=xxx
     */
    @Override
    @GetMapping
    @ApiImplicitParam(name = "num",value = "编号",required = true,paramType = "query")
    public Student modifyStudentNum(@RequestParam("num") String num) {
        Student student = new Student(num, "xiaohong", 10, "parts");
        return student;
    }

    /**
     * 测试Restful风格的参入参数
       path(Restful):
       get	http://ip:port/rootPath/stu/xxxx
     */
    @Override
    @GetMapping("{name}")
    @ApiImplicitParam(name = "name",value = "名称",required = true,paramType = "path")
    public Student modifyStudentName(@PathVariable("name") String name) {
        Student student = new Student("002", name, 10, "parts");
        return student;
    }

    /**
     * 测试json格式的传入参数
       请求体传参(json格式的数据):
       	post http://ip:port/rootPath/stu
       	requestBody：
        {
        	"xxxxx"："xxxx"
        }
     */
    @Override
    @PostMapping
    @ApiImplicitParam(name = "student",value = "这是个啥",required = true,paramType = "body")
    public Student modifyStudent(@RequestBody Student student) {
        student.setName("modifyName");
        return student;
    }


    /**
     * 测试 queryString 、Restful 和 json 格式的参数
       put	http://ip:port/rootPath/stu/xxxx?name=xxx
       	requestBody：
        {
        	"xxxxx"："xxxx"
        }
     */
    @Override
    @PutMapping("{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "编号", required = true, paramType = "path", dataType = "string"),
            @ApiImplicitParam(name = "name", value = "名称", required = true, paramType = "query", dataType = "string")

    })
    public Student mofidyStudentBynNum(@PathVariable("id") String id, @RequestParam("name") String name, @RequestBody Student student) {
        student.setName(name);
        student.setStuNo(id);
        return student;
    }

}